$regfile = "m16def.dat"
$crystal = 8000000

'Inisialisasi variable Global
Dim Input_pinb As Integer , Icounter As Integer
Dim Winput_adc(0 to 7) As Word
Dim wRef_adc(0 to 7) As Word

'Fungsi Utama
fMain:
    Call Inisialisasi
    Lcd "W E L C O M E"                                          
    Waitms 1000
    Portc = 0
End

'Fungsi Interupsi Timer0
Fint_handle_timer0:
   Dim iChannel = 0 As Integer
   'Baca data input ADC
   For iChannel = 0 to 7 Do
       Winput_adc(iChannel) = Getadc(iChannel)
       If Winput_adc(iChannel) > wRef_adc(iChannel) Then
           PORTC = PORTC AND &HFE
       End If
   Next iCannel

   Input_pinb = Pinb And 1
   'Input_pinb = 0
   If Pinb.0 = 0 Then
      Portc = &H0F
   End If
Return                   

'Inisialisasi
Inisialisasi:
    Dim A As Byte
    
    'Inisialisasi LCD
    Config Lcd = 16 * 2                                         
    Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.2 , Rs = Portd.0
    Initlcd
    Cls                                                         
    
    'Inisialisasi Port
    Config Portc = Output
    Config Portd = Output
    Portd = 0
    Portc = &HF0	
    
    'Inisialisasi Timer0
    Config Timer0 = Timer , Prescale = 1024
  
    'Inisialisasi ADC
    Config Adc = Single , Prescaler = Auto

    'Inisialisasi Interupsi
    Enable Interrupts
    '-Inisialisasi Interupsi Timer0
    Enable Timer0 
    On Timer0 Fint_handle_timer0
    Start Timer0
    
    'Inisialisasi variable awal
    Icounter = 0

Return